<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//输入：numbers = [2,7,11,15], target = 9
			//输出：[1,2]
			//解释：2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。
			/**
			 * @param {number[]} numbers
			 * @param {number} target
			 * @return {number[]}
			 */
			var twoSum = function(numbers, target) {
				let i = 0;
				let j = numbers.length - 1;
				while (i < j) {
					if (numbers[i] + numbers[j] == target) {
						return [i + 1, j + 1];
					} else if (numbers[i] + numbers[j] > target) {
						j--;
					} else {
						i++;
					}
				}
				return -1;
			};
			console.log(twoSum([2, 7, 11, 15], 20));
		</script>
	</body>
</html>
